﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib prefix="ism" uri="http://www.baseproj.org/rd/html" %>
<div class="editBlock search">
    <form action="" method="post" id="statForm">
        <input type="hidden" id="projectCode" name="projectCode" value="<s:property value='projectCode' />"/> <input
            type="hidden" id="schemeCode" name="schemeCode"
            value="<s:property value='schemeCode' />"/>
        <table>
            <tbody>
            <tr>
                <th>统计类型</th>
                <td><s:select onchange="searchStat()"
                              list="@baseproj.common.constants.EnumUtil@getValues(@com.rd.sys.dto.commmon.enums.AnalysisEnum$StatType@values())"
                              name="statType"
                              id="statType"/></td>
                <th><span id="resultCode_stat_th">结果名</span>
                </th>
                <td><s:select onchange="searchStat()"
                              list="@com.rd.sys.common.utils.List2SelectUtil@getValues(resultList,true)"
                              name="resultCode" id="resultCode_stat"/>
                </td>
                <th><span id="materialCode_stat_th">素材名</span></th>
                <td><s:select onchange="searchStat()"
                              list="@com.rd.sys.common.utils.List2SelectUtil@getValues(materialList,true)"
                              name="materialCode" id="materialCode_stat"/>
                </td>
                <th></th>
                <td><input type="button" class="inputButton" value="导出" onclick="exportStat()"/>
                </td>
            </tr>
            <!-- <input id="searchButton" name="searchButton" type="button" class="inputButton" value="查询" onclick="searchStat()" /> -->
            </tbody>
        </table>
    </form>
</div>
<div class="dataGrid" id="statDataGrid">
    <jsp:include page="statistic_fixation.jsp"></jsp:include>
</div>
<form action="" method="post" id="exportForm" target="exportFrame"></form>
<iframe name="exportFrame" style="display: none"></iframe>
<ism:script type="text/javascript" src="../js/analysis/statistic_core.js" debug="false"></ism:script>
<script type="text/javascript">
    $(function () {
        closeLoad(); //当进入该页面时,关闭加载层
    });

    function searchStat() {
        loading();
        prepareCondition();

        ajaxLoading($("#statDataGrid"), "statistic_index.action", $("#statForm").serialize(), function (status) {
            loadErrorFunction(status);
            initDatagrid(); //重新初始化表格,主要是奇偶行样式
            closeLoad();
        });
    }

    function queryByPage(currentPage, pageSize, totalPage, totalCount) {
        var queryParams = $("#statForm").serialize();
        var url = "statistic_index.action?" + queryParams + "&page.currentPage=" + currentPage + "&page.pageSize=" + pageSize + "&page.totalPage=" + totalPage + "&page.totalCount=" + totalCount;

        loading();

        ajaxLoading($("#statDataGrid"), url, null, function (status) {
            loadErrorFunction(status);
            initDatagrid(); //重新初始化表格,主要是奇偶行样式
            closeLoad();
        });
    }

    /** 查询条件过滤 */
    function prepareCondition() {
        var statType = $("#statType").val();
        //素材类型时不显示结果条件
        if (statType == '<s:property value="@com.rd.sys.dto.commmon.enums.AnalysisEnum$StatType@MATERIAL.getCode()"/>'
        ) {
            $("#resultCode_stat").hide();
            $("#resultCode_stat_th").hide();
        } else {
            $("#resultCode_stat").show();
            $("#resultCode_stat_th").show();
        }

        //结果类型时不显示素材条件
        if (statType == '<s:property value="@com.rd.sys.dto.commmon.enums.AnalysisEnum$StatType@RESULT.getCode()"/>' ||
            statType == '<s:property value="@com.rd.sys.dto.commmon.enums.AnalysisEnum$StatType@EVENT.getCode()"/>') {
            $("#materialCode_stat").hide();
            $("#materialCode_stat_th").hide();
        } else {
            $("#materialCode_stat").show();
            $("#materialCode_stat_th").show();
        }
    }

    /** 导出统计报表 */
    function exportStat() {
        var url = "statistic_export.action?" + $("#statForm").serialize();
        $("#exportForm").attr("action", url);
        $("#exportForm").submit();
    }

    /** 导出原始数据 */
    function exportResultRawData(resultCode) {
        var url = "statistic_exportRawData.action?resultCode=" + resultCode + "&projectCode=" + $("#projectCode").val() + "&schemeCode=" + $("#schemeCode").val();
        $("#exportForm").attr("action", url);
        $("#exportForm").submit();
    }
</script>
